const app = getApp()

Page({
  data: {

  },
  doRegist: function (e) {
    var formObj = e.detail.value;
    var username = formObj.username;
    var password = formObj.password;
    //简单验证
    if (username.length == 0 || password.length == 0) {
      wx.showToast({
        title: '账号或密码不能为空~',
        icon: 'none',
        duration: 3000 //持续时间3秒
      })
    } else {
      wx.showLoading({
        title: '请等待...',
      });
      var serverUrl = app.serverUrl;
      wx.request({
        url: serverUrl + '/usrBaseOperation/register',
        method: "POST",
        data: {
          username: username,
          password: password
        },
        header: {
          'content-type': 'application/json' //默认值
        },
        success: function (result) {
          wx.hideLoading();
          var status = result.data.status;
          if (status == 200) {
            wx.showToast({
              title: "注册成功了呦~",
              icon: 'none',
              duration: 3000 //持续时间3秒
            });
            app.setGlobalUserInfo(result.data.data);
            //跳转到个人主页
            wx.redirectTo({
              url: '../mine/mine',
            });
          } else if (status == 500) {
            wx.showToast({
              title: result.data.msg,
              icon: 'none',
              duration: 3000 //持续时间3秒
            })
          }
        }
      })
    }
  },
  goLoginPage: function () {
    wx.redirectTo({
      url: '../userLogin/login',
    })
  }
})